using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Media.Imaging;
using Legacy.Core.SaveGameManagement;

namespace MMXSaveGameConverter
{
    internal abstract class FileReaderBase
    {
        public abstract IReaderState Read();
        public abstract SaveFileMeta ReadFileMeta(IReaderState readerState);
        public abstract SaveGameMeta ReadSaveMeta(IReaderState readerState);
        public abstract SaveGame ReadSaveGame(IReaderState readerState, SaveGameMeta saveMeta);
        public abstract BitmapFrame ReadScreenshot(IReaderState readerState);

        public void SetMeta(SaveGameViewItem item)
        {
            using (IReaderState state = Read())
            {
                SaveFileMeta fileMeta = ReadFileMeta(state);
                SaveGameMeta saveMeta = ReadSaveMeta(state);
                if (saveMeta.Time.Year == 0001)
                    throw new InvalidDataException();

                item.SetMeta(fileMeta, saveMeta);
            }
        }
    }
}